package com.wxxymakers.cklabrecruit.mapper;

import com.wxxymakers.cklabrecruit.entity.User;
import com.wxxymakers.cklabrecruit.entity.UserExample;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    long countByExample(UserExample example);

    int deleteByExample(UserExample example);

    @Delete({
        "delete from user",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into user (username, password, ",
        "role, datetime)",
        "values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
        "#{role,jdbcType=VARCHAR,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}, ",
        "#{datetime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    @Select({
        "select",
        "Id, username, password, role, datetime",
        "from user",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.wxxymakers.cklabrecruit.mapper.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "Id, username, password, role, datetime",
            "from user",
            "where username = #{username}"
    })
    @ResultMap("com.wxxymakers.cklabrecruit.mapper.UserMapper.BaseResultMap")
    User selectByUsername(String username);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    @Update({
        "update user",
        "set username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "role = #{role,jdbcType=VARCHAR},",
          "datetime = #{datetime,jdbcType=TIMESTAMP}",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);
}